<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../common.inc" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%java.util.Random r=new java.util.Random();  %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="./css/style1.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="./js/form.js"></script>
<script type="text/javascript" language="javascript">
<!--

	function checkForm(){
		var objs = document.getElementsByName("id");
		var sign = 0;
		for(var i = 0; i < objs.length; i++){
			if(objs[i].value != 0 && objs[i].checked)sign = sign + 1;
		}
		if(sign <= 0){
			alert("<fmt:message key='openSea.message.protect'/>");
			return false;
		}
		return true;
	}
	
	function checkForm2(){
		var objs = document.getElementsByName("id");
		var sign = 0;
		for(var i = 0; i < objs.length; i++){
			if(objs[i].value != 0 && objs[i].checked)sign = sign + 1;
		}
		if(sign <= 0){
			alert("请选择待操作的项！");
			return false;
		}else if(sign > 1){
			alert("只能选择一个待操作项！");
			return false;
		}
		return true;
	}

	function batchImport(){
		window.location.href = "./openCustomer.do?action=openBatchImport";
		window.location.target = "main";
	}
	
	/**
	function batchImportLinkman(){
		if(checkForm2()){
			var objs = document.getElementsByName("id");
			var id = 0;
			for(var i = 0; i < objs.length; i++){
				if(objs[i].value != 0 && objs[i].checked){
					id = objs[i].value;
					break;
				}
			}
			window.location.href = "./openCustomer.do?action=openBatchImportByLinkman&customerId="+id;
			window.location.target = "main";
		}
	}*/
	
	function searchCustomer(){
		var customerName = document.getElementById("customerName");
		if(customerName.value == ""){
			alert("<fmt:message key='openSea.message.search'/>");
		}else{
			document.getElementById("sFlag").value = "1";
			document.openCustomerForm.action = "./openCustomer.do";
			document.openCustomerForm.target = "main";
			document.openCustomerForm.submit();
		}
	}
	
	function pageCustomer(flag){
		document.openCustomerForm.action = "./openCustomer.do?action=display&flag="+flag;
		document.openCustomerForm.target = "main";
		document.openCustomerForm.submit();
	}
	
	function protectCustomer(){
		var untappedCustomerNum = "<c:out value='${customerLimitForm.untappedCustomerNum}'/>";
		var isExpUser = "<c:out value='${isExpUser}'/>";
		if(checkForm()){
			var objs = document.getElementsByName("id");
			var sign = 0;
			for(var i = 0; i < objs.length; i++){
				if(objs[i].value != 0 && objs[i].checked)sign = sign + 1;
			}
		
			if(isExpUser == 1 || sign <= untappedCustomerNum){
				document.openCustomerForm.action = "./openCustomer.do?action=protectCustomer";
				document.openCustomerForm.target = "main";
				document.openCustomerForm.submit();
				
			}else if(untappedCustomerNum <= 0){
				alert("<fmt:message key='openSea.message.overstep'/>");
			}else{
				alert("<fmt:message key='openSea.message.currentpro'/>"+untappedCustomerNum+"<fmt:message key='customer.message.num'/>");
			}
		}
	}
	
	function advancedQueryDialog(){
		var url = "./openCustomer.do?action=advancedQueryCustomer&radom="+<%=r.nextInt(100)%>;
		var dlgParam = "dialogHeight:360px;dialogWidth:450px;dialogTop:300px;dialogLeft:400px;status:no;help:no;scrollbars:yes;";
		var rt = window.showModalDialog(url,"",dlgParam);
		if(rt != undefined){		
			//根据从子窗口得到的值，从中提取customerName,industryId,areaId,startLastLinkDate,endLastLinkDate
			var tStr = rt.split(",");
			document.getElementById("customerName2").value = tStr[0];
			document.getElementById("industryId").value = tStr[1];
			document.getElementById("areaId").value = tStr[2];
			document.getElementById("startLastLinkDate").value = tStr[3];
			document.getElementById("endLastLinkDate").value = tStr[4];
			
			document.getElementById("sFlag").value = "2";
			document.openCustomerForm.action = "./openCustomer.do";
			document.openCustomerForm.target = "main";
			document.openCustomerForm.submit();
		}
	}
	
	function initPage(){
		if("<c:out value='${result}'/>" == 1){
			alert("<fmt:message key='openSea.message.success'/>");
		}
	}
-->
</script>
</head>
<body onload="initPage()">
<form name="openCustomerForm" action="" method="post">
	<table class="table_frame">
		<tr>
			<td>
				<table class="table_title1">
					<tr>
						<td class="title_lab" colspan="2">公海客户</td>
					</tr>
					<tr>
						<td valign="bottom" class="a_tools" style="padding-left: 3px;"><fmt:message key='openSea.lable.search'/>
							<input id="customerName" name="customerName" class="input_query" type="text" value="${customerName}"/>
							<a class="search" href="javascript:searchCustomer();" target="main" hidefocus="true">查询</a>
							|
							<a class="asearch" href="javascript:advancedQueryDialog();" hidefocus="true">高级查询</a>
							|
							<c:if test="${isProtectOpenCustomer == 1}">
							<a class="protect" href="javascript:protectCustomer();" hidefocus="true">保护</a>
							</c:if>
							<c:if test="${isImportOpenCustomer == 1}">
							<a class="import" href="javascript:batchImport();" hidefocus="true">导入客户</a>
							<!-- &nbsp;&nbsp;
							<a href="javascript:batchImportLinkman();" hidefocus="true">导入联系人</a>
							 -->
							</c:if>
						</td>
						<td></td>
					</tr>
					<tr><td colspan="2" height="2"></td></tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>
				<table class="table_title2">
					<tr>
						<td class="title_lab">公海客户</td>
						<td valign="bottom">
							<table class="table" style="font-weight: bold;">
								<tr>
									<td align="left">&nbsp;
										<img src="./images/limit1.jpg" style="vertical-align: middle;"/>&nbsp;<font class="font_bule">已保护</font>：
										<font class="font_orange">${customerLimitForm.currentCustomerNum}</font>&nbsp;<fmt:message key='common.lable.a'/>&nbsp;&nbsp;
										<img src="./images/limit2.jpg" style="vertical-align: middle;"/>&nbsp;<font class="font_bule">保护上限</font>：
										<c:choose>
											<c:when test="${isExpUser == 1}"><font class="font_orange">无限制</font></c:when>
											<c:otherwise><font class="font_orange">${customerLimitForm.totalCustomerLimit}</font>&nbsp;<fmt:message key='common.lable.a'/></c:otherwise>
										</c:choose>&nbsp;&nbsp;
										<img src="./images/limit3.jpg" style="vertical-align: middle;"/>&nbsp;<font class="font_bule">可保护</font>：
										<c:choose>
											<c:when test="${isExpUser == 1}"><font class="font_orange">无限制</font></c:when>
											<c:otherwise><font class="font_orange">${customerLimitForm.untappedCustomerNum}</font>&nbsp;<fmt:message key='common.lable.a'/></c:otherwise>
										</c:choose>
									</td>
								</tr>
							</table>
						</td>
						<td align="right" valign="">
							<!-- page -->
							<table class="table_page2">
								<tr>
									<td valign="bottom">
										<img src="./images/frist.bmp" onclick="pageCustomer(1)" alt="首页" style="vertical-align: middle;cursor: hand;">
										<img src="./images/last.bmp" onclick="pageCustomer(2)" alt="上一页" style="vertical-align: middle;cursor: hand;">&nbsp;
										<font color="red">${currentPage}</font>/${totalPages}&nbsp;<fmt:message key='common.page'/>&nbsp;
										<img src="./images/next.bmp" onclick="pageCustomer(3)" alt="下一页" style="vertical-align: middle;cursor: hand;">
										<img src="./images/end.bmp" onclick="pageCustomer(4)" alt="末页" style="vertical-align: middle;cursor: hand;">
										共&nbsp;&nbsp;${totalRows}&nbsp;<fmt:message key='common.page.totalRow'/>&nbsp;&nbsp;&nbsp;
									</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr><td colspan="3" height="2"></td></tr>
					<tr>
						<td colspan="3" valign="top">
							<table class="table">
								<tr>
									<td valign="top">
										<!-- 
										<div style="width:800px;height:100%;overflow-x: scroll;overflow-y: hidden;">
										 -->
										<table class="table_style">
											<tr>
												<td class="title" width="8"></td>
												<td class="title" width="30">
													选择
													<!-- 
													<input id="id" name="id" type="checkbox" value="0" onclick="checkAll('id')"/>
													 -->
												</td>
												<td class="title"><fmt:message key='customer.lable.customerName'/></td>
												<td class="title" width="12%">行业</td>
												<td class="title" width="12%">区域</td>
												<td class="title" width="12%"><fmt:message key='customer.lable.linkmanNum'/></td>
												<td class="title" width="12%"><fmt:message key='openSea.lable.linkNum'/></td>
												<td class="title" width="12%"><fmt:message key='customer.lable.lastlink'/></td>
											</tr>
											<c:choose>
											<c:when test="${not empty customers}">
												<c:forEach var="customer" items="${customers}">
												<tr onmouseover="onmousemoveChange(this,'img${customer.id}')" onmouseout="onmouseoutChange(this,'img${customer.id}')">
													<td height="16" width="8" align="right"><img id="img${customer.id}" src="./images/table_sign2.bmp"></td>
													<td><input id="id" name="id" type="checkbox" value="${customer.id}"/></td>
													<td align="left">${customer.customerName}</td>
													<td>
														<c:forEach var="range" items="${ranges['110']}">
															<c:if test='${customer.industryId == range.id}'>${range.rangeValue}</c:if>
														</c:forEach>
													</td>
													<td>
														<c:forEach var="range" items="${ranges['111']}">
															<c:if test='${customer.areaId == range.id}'>${range.rangeValue}</c:if>
														</c:forEach>
													</td>
													<td>${customer.linkmanNum}</td>
													<td>${customer.linkNum}</td>
													<td><fmt:formatDate value="${customer.lastLink}" pattern="yyyy-MM-dd"/></td>
												</tr>
												</c:forEach>
											</c:when>
											<c:otherwise>
												<tr><td colspan="8" align="center"><img src="./images/nodata.bmp"></td></tr>
											</c:otherwise>
											</c:choose>
										</table>
										<!-- 
										</div>
										 -->
									</td>
								</tr>
								<tr>
									<td align="left" valign="bottom">
										<!-- page -->
										<table id="tp" class="table_page">
											<tr>
												<td>&nbsp;&nbsp;
													<img src="./images/frist.bmp" onclick="pageCustomer(1)" alt="首页" style="vertical-align: middle;cursor: hand;">
													<img src="./images/last.bmp" onclick="pageCustomer(2)" alt="上一页" style="vertical-align: middle;cursor: hand;">&nbsp;
													<font color="red">${currentPage}</font>/${totalPages}&nbsp;<fmt:message key='common.page'/>&nbsp;
													<img src="./images/next.bmp" onclick="pageCustomer(3)" alt="下一页" style="vertical-align: middle;cursor: hand;">
													<img src="./images/end.bmp" onclick="pageCustomer(4)" alt="末页" style="vertical-align: middle;cursor: hand;">
													共&nbsp;&nbsp;${totalRows}&nbsp;<fmt:message key='common.page.totalRow'/>
												</td>
											</tr>
										</table>
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
	<input id="customerName2" name="customerName2" type="hidden" value="${queryCustomer.customerName2}"/>
	<input id="industryId" name="industryId" type="hidden" value="${queryCustomer.industryId}"/>
	<input id="areaId" name="areaId" type="hidden" value="${queryCustomer.areaId}"/>
	<input id="startLastLinkDate" name="startLastLinkDate" type="hidden" value="${queryCustomer.startLastLinkDate}"/>
	<input id="endLastLinkDate" name="endLastLinkDate" type="hidden" value="${queryCustomer.endLastLinkDate}"/>
	<input id="sFlag" name="sFlag" type="hidden" value="${sFlag}"/>
</form>
</body>
</html>